package com.liu.StatisticService.controller;


import com.liu.R;
import com.liu.StatisticService.service.StatisticsDailyService;
import com.liu.serviceBase.exception.MyException;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author LSJ
 * @since 2022-02-14
 */
@RestController
@RequestMapping("/StatisticService/statistics")
@CrossOrigin
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    // 统计某天的注册人数
    @PostMapping("registerCount/{day}")
    public R registerCount(@PathVariable String day){
        if (ObjectUtils.isEmpty(day)){
            throw  new MyException(20001,"StatisticsDailyControllerd 的day为空");
        }
        statisticsDailyService.registerCount(day);
        return R.ok().message("统计已入表");

    }

    // 统计返回不同类型的日期、数据
    @GetMapping("showData/{type}/{begin}/{end}")
    public R showData(@PathVariable String type, @PathVariable String begin, @PathVariable String end){
//        需要获取x（日期数组）、y轴（数量数组）数据
      Map<String,Object> map =   statisticsDailyService.showData(type,begin,end);

      return R.ok().data("map",map);

    }

}

